<template>
  <div>
    <div class="list clearfix">
        <router-link 
            tag="div"
            :to="{name:'Player',params:{id:item.id,name:item.name,author:item.tags[1],image:encodeURIComponent(item.coverImgUrl)}}"
            class="item" 
            v-for="(item,index) in detailsData" 
            :key="index"
            :class="{'clear-padding' : index%3 !== 1}"
        >
            <div class="img-warpper">
                <img :src="item.coverImgUrl">
            </div>
            <div class="main">{{cutString(item.name)}}</div>
            <div class="gray">{{cutString(item.tags[1])}}</div>
        </router-link>
    </div>
  </div>
</template>

<script>
export default {
    name:"Details",
    data(){
        return {
            detailsData:[]
        }
    },
    mounted(){
        this.$api.getMusicDetails({
            id:this.$route.params.id,
            // limit:15
        }).then(res => {
            // console.log(res);
            this.detailsData = res.playlists;
        })
    },
    methods:{
        //让文字显示在一行上，超出则打点
        cutString(str){
            if(str){
                if(str.length > 8){
                    return str.substring(0, 8) + "..."
                }
                return str;
            }
            return "";
        }
    }
}
</script>

<style scoped>
.list {
    width: 100%;
}

.list .item {
    float: left;
    width: 31.33%;
    padding: 0 10px;
    margin-bottom: 10px;
}

.clear-padding {
    padding: 0 !important;
}

.main {
    margin-top: 4px;
    font-size: 12px;
}

.gray {
    font-size: 12px;
    color: #999;
}

.btn-more {
    font-size: 12px;
    text-align: right;
    color: #333;
}
</style>